from sqlmodel import SQLModel, Field
from typing import Optional
from datetime import datetime


class TargetType(str):
    BINARY = "binary"
    SOURCE = "source"
    WEB = "web"
    API = "api"
    MOBILE = "mobile"


class Target(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    name: str = Field(..., description="目标名称")
    description: Optional[str] = Field(default=None, description="目标描述")
    type: str = Field(..., description="目标类型")
    target_path: str = Field(..., description="目标路径或URL")
    source_location: Optional[str] = Field(default=None, description="源代码位置")
    build_command: Optional[str] = Field(default=None, description="构建命令")
    environment_config: Optional[str] = Field(default=None, description="环境配置（JSON格式）")
    is_active: bool = Field(default=True, description="是否激活")
    created_at: datetime = Field(default_factory=datetime.now, description="创建时间")
    updated_at: datetime = Field(default_factory=datetime.now, description="更新时间")
    
    class Config:
        arbitrary_types_allowed = True